package com.suxin.plugin.intergration.factory;

import com.suxin.plugin.intergration.manager.PluginWrapper;
import com.suxin.plugin.pf4j.BasePlugin;

import java.util.*;

/**
 * @author Tang
 * @classname PluginRegistryInfo
 * @description [ 注册的插件信息 ]
 * @date 2022/7/20 00:31
 */
public class PluginRegistryInfo {

    private PluginWrapper pluginWrapper;
    private BasePlugin plugin;
    private String pluginId;

    // 插件中所有加载出来的class信息
    private List<Class<?>> classes = new ArrayList<>();

    /**
     * 分组的class信息
     */
    private Map<String, List<Class<?>>> groupClass = new HashMap<>();

    public PluginRegistryInfo(PluginWrapper pluginWrapper) {
        this.pluginWrapper = pluginWrapper;
        this.plugin = this.pluginWrapper.getPlugin();
        this.pluginId = this.getPluginWrapper().getPluginDescriptor().getPluginId();
    }

    public List<Class<?>> getClasses() {
        return classes;
    }

    public void setClasses(List<Class<?>> classes) {
        this.classes = classes;
    }

    public Map<String, List<Class<?>>> getGroupClass() {
        return groupClass;
    }

    public void setGroupClass(Map<String, List<Class<?>>> groupClass) {
        this.groupClass = groupClass;
    }

    public PluginWrapper getPluginWrapper() {
        return pluginWrapper;
    }

    public BasePlugin getPlugin() {
        return plugin;
    }

    public String getPluginId() {
        return pluginId;
    }

    /**
     * 添加到组class
     * @param groupId
     * @param aClass
     */
    public void addGroupClass(String groupId, Class<?> aClass) {
        groupClass.compute(groupId, (key, value) -> {
            if (Objects.isNull(value)) {
                return new ArrayList<>(10);
            }
            value.add(aClass);
            return value;
        });
    }

    /**
     * 添加class
     * @param aClass
     */
    public void addClasses(Class<?> aClass){
        if(aClass != null){
            classes.add(aClass);
        }
    }

}
